package com.hugang.designmode.proxy;

/**
 * 代理模式：静态代理
 *
 * @author hg
 * @date 2020/6/12 16:45
 */
public class StaticProxyTest {

    public static void main(String[] args) {
        Network network = new Server();
        ProxyServer proxyServer = new ProxyServer(network);
        proxyServer.browse();
    }

}


interface Network {
    void browse();
}

/**
 * 被代理类：真实服务器
 * @author hg
 * @date 2020/6/12
 */
class Server implements Network{

    @Override
    public void browse() {
        System.out.println("真实的服务器访问网络");
    }
}

/**
 * 代理类
 * @author hg
 * @date 2020/6/12
 */
class ProxyServer implements Network{

    private Network target;

    public ProxyServer(Network target){
        this.target = target;
    }

    @Override
    public void browse() {
        check();
        target.browse();
    }

    public void check(){
        System.out.println("联网之前的检查工作");
    }
}
